package com.Sinewecology.EntropyWechat;

import java.util.List;

public class NewsMessage {
	//接收方帐号
	private String toUserName;
	//开发者微信号
	private String fromUserName;
	//消息创建时间
	private long createTime;
	//消息类型
	private String msgType = MessageUtil.RESP_MESSAGE_TYPE_NEWS;
	//图文消息个数
	private int articleCount;
	//图文列表
	private List<Article> articles;
	public String getToUserName() {
		return toUserName;
	}
	public void setToUserName(String toUserName) {
		this.toUserName = toUserName;
	}
	public String getFromUserName() {
		return fromUserName;
	}
	public void setFromUserName(String fromUserName) {
		this.fromUserName = fromUserName;
	}
	public long getCreateTime() {
		return createTime;
	}
	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}
	public String getMsgType() {
		return msgType;
	}
	public void setMsgType(String msgType) {
		this.msgType = msgType;
	}
	public int getArticleCount() {
		return articleCount;
	}
	public List<Article> getArticles() {
		return articles;
	}
	public void setArticles(List<Article> articles) {
		this.articles = articles;
		articleCount = articles.size();
	}
	@Override
	public String toString(){
		StringBuffer msg = new StringBuffer();
		msg.append("<xml>");
		msg.append("<ToUserName><![CDATA["+toUserName+"]]></ToUserName>");
		msg.append("<FromUserName><![CDATA["+fromUserName+"]]></FromUserName>");
		msg.append("<CreateTime>"+createTime+"</CreateTime>");
		msg.append("<MsgType><![CDATA["+msgType+"]]></MsgType>");
		msg.append("<ArticleCount>"+articleCount+"</ArticleCount>");
		msg.append("<Articles>");
		for(int i=0;i<articleCount;i++){
			Article a = articles.get(i);
			msg.append("<item>");
			msg.append("<Title><![CDATA["+a.getTitle()+"]]></Title>");
			msg.append("<Description><![CDATA["+a.getDescription()+"]]></Description>");
			msg.append("<PicUrl><![CDATA["+a.getPicUrl()+"]]></PicUrl>");
			msg.append("<Url><![CDATA["+a.getUrl()+"]]></Url>");
			msg.append("</item>");
		}
		msg.append("</Articles>");
		msg.append("</xml>");
		return msg.toString();
	}
}
